<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *报名管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择装修申请单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'订单列表'),	
);

$return['status']=array('0'=>'未提交','1'=>'已提交','3'=>'已取消','4'=>'已完成');
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['ordersn'])){
		$params['ordersn like']='%'.trim($_RQ['ordersn']).'%';
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','user_id','cid','sid','ordersn','money','pay','address','area','image','remark','status','createtime');
	$list=pdo_getslice('jy_cmsdecorate_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['c_title']=pdo_getcolumn('jy_cmsdecorate_company',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['cid']),'title');
			$item['s_name']=pdo_getcolumn('jy_cmsdecorate_stylist',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['sid']),'name');
			$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['user_id']));
			$item['realname']=$member['realname'];
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$item['mobile']=$member['mobile'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'ordersn','title'=>'申请单号','type'=>'string'),
			array('name'=>'c_title','title'=>'公司名称','type'=>'string'),
			array('name'=>'nickname','title'=>'设计师名称','type'=>'string'),
			array('name'=>'realname','title'=>'用户姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'用户电话','type'=>'string'),
		  //array('name'=>'pay','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'ordersn','title'=>'单号','type'=>'string','width'=>'15'),
		//	array('name'=>'s_name','title'=>'设计师名称','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'select','options'=>'status_select','width'=>'15'),
		)
	);
	$return['status_select']=array(array('id'=>'0','title'=>'未提交'),array('id'=>'1','title'=>'已提交'),array('id'=>'3','title'=>'已取消'),array('id'=>'4','title'=>'已完成'));
	$return['htmls']=$htmls;
	exi($return);
}
//确认报名操作
if($_RQ['op']=='confirm'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsdecorate_order',array('status'=>'2'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('确认订单成功！');
}
//取消报名操作
if($_RQ['op']=='cancel'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsdecorate_order',array('status'=>'3'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('取消订单成功！');
}
//同意退款
if($_RQ['op']=='agree'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsdecorate_order',array('status'=>'6'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('已同意退款申请！');
}
//拒绝退款操作
if($_RQ['op']=='disagree'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsdecorate_order',array('status'=>'7'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('已拒绝退款申请！');
}